<template>
  <div class="comment-reply">
    <!-- navbar -->
    <van-nav-bar class="page-bav-bar">
      <div slot="title">
        {{
          comment.reply_count > 0
            ? `有${comment.reply_count}条回复`
            : "暂无回复"
        }}
      </div>
      <template #right>
        <van-icon name="cross" size="18" @click="$emit('close-reply')" />
      </template>
    </van-nav-bar>
    <!-- navbar -->

    <div class="scroll-wrap">
      <!-- 标题 评论项 -->
      <van-cell title="评论项内容" style="bacground: #fafafa" />
      <CommentItem :comment="comment"></CommentItem>

      <!-- 标题 评论项 -->
      <van-cell title="评论项内容" style="bacground: #fafafa" />
      <CommentList
        :list="commentLists"
        :source="comment.com_id"
        type="'c'"
      ></CommentList>
    </div>

    <!-- 回复评论按钮 -->
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        @click="isPostShow = true"
        size="small"
        round
        >写评论</van-button
      >
    </div>

    <!-- 评论弹出层 -->
    <van-popup v-model="isPostShow" position="bottom">
      <CommentPost
        @onsuccess-post="onSuccessPost"
        :target="comment.com_id"
        type="c"
      ></CommentPost>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },

  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      commentLists: []
    }
  },
  computed: {},
  watch: {},
  created () {
    console.log(this.comment)
  },
  mounted () {},
  methods: {
    onSuccessPost (comment) {
      this.isPostShow = false
      console.log(comment)
      this.commentLists.unshift(comment.new_obj)
    }
  }
}
</script>
<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
</style>
